#include "logicBinaryOperation.h"

LogicBinaryOperation::LogicBinaryOperation(Expression* leftExpresion, std::string opRep, Expression* rightExpression)
{
	if(leftExpresion != NULL) leftOperand =leftExpresion->clone();
	else leftOperand = NULL;

	operatorRepresentation = opRep;

	if(rightExpression != NULL) rightOperand = rightExpression->clone();
	else rightOperand = NULL;
}

LogicBinaryOperation::LogicBinaryOperation(const LogicBinaryOperation & other)
{
    if(other.leftOperand != NULL) leftOperand =other.leftOperand->clone();
	else leftOperand = NULL;

	operatorRepresentation = other.operatorRepresentation;

	if(other.rightOperand != NULL) rightOperand = other.rightOperand->clone();
	else rightOperand = NULL;
}

LogicBinaryOperation::~LogicBinaryOperation()
{
    delete leftOperand; leftOperand = NULL;
    delete rightOperand; rightOperand = NULL;
    operatorRepresentation = "";
}

std::string LogicBinaryOperation::toString()
{
    std::string str = "(";
    if(leftOperand != NULL) str = str + leftOperand->toString();
    str = str + " " + operatorRepresentation + " ";
    if(rightOperand != NULL) str = str + rightOperand->toString();
    return str + ")";
}

Expression * LogicBinaryOperation::clone()
{
    return new LogicBinaryOperation(*this);
}

Expression * LogicBinaryOperation::getRightExpression()
{
    return rightOperand;
}

Expression * LogicBinaryOperation::getLeftExpression()
{
    return leftOperand;
}

void LogicBinaryOperation::setRightExpression(Expression * expression)
{
    delete rightOperand; rightOperand = NULL;
    if(expression != NULL) rightOperand = expression->clone();
}

void LogicBinaryOperation::setLeftExpression(Expression * expression)
{
    delete leftOperand; leftOperand = NULL;
    if(expression != NULL) leftOperand = expression->clone();
}

void LogicBinaryOperation::setOperator(const std::string & opRep)
{
    operatorRepresentation = opRep;
}

std::string LogicBinaryOperation::getOperator()
{
    return operatorRepresentation;
}
